# -*- coding: utf-8 -*-
# @Time    : 2020/5/12
# @Author  : nanjiang.xie
# @File    : dataUtils.py

"""
封装数据生成相关关键字
"""

import uuid
import string
import random
import time
import datetime


def rand_uuid():

    """
    随机产生一个32位的uuid
    - :return: 返回uuid
    """
    temp = str(uuid.uuid1())
    return temp.replace("-", "")


def rand_name(prefix=None, length=5):
    """产生随机名字

    - :param prefix: 【选填】名字的前缀，可选值，类型：string
    - :param length: 【选填】名字的后缀的长度,类型：int
    - :return: 返回随机名字
    """
    rand_str = "".join(random.sample(string.digits, int(length)))
    str1_temp = rand_str if not prefix else prefix + rand_str
    return str1_temp


def rand_str(length):
    """随机产生指定长度的字符串

    - :param length: 【必填】字符串长度，类型：int
    - :return: 返回字符串
    """

    char = string.ascii_letters + string.digits + string.punctuation
    rand_str1 = "".join(random.choice(char) for x in range(int(length)))
    return rand_str1


def get_time_stamp():
    """获取时间戳

    - :return:返回时间戳
    """
    temp_time = str(int(time.time()*1000))
    return temp_time


# def get_time_stamp_formatted(formatter="%Y-%m-%d %H:%M:%S"):
    """获取格式化后的时间戳

    - :return:返回格式化后的时间戳
    """
    # temp_time = time.strftime(formatter, time.localtime(time.time()))
    # return temp_time


def time_delta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0):
    """在当前时间基础上进行时间增减操作

    - :param days:  【可选】单位：天；类型：整数
    - :param seconds: 【可选】单位：秒；类型：整数
    - :param microseconds: 【可选】单位：毫秒；类型：整数
    - :param milliseconds: 【可选】单位：千毫秒；类型：整数
    - :param minutes:【可选】单位：分钟；类型：整数
    - :param hours:【可选】单位：小时；类型：整数
    - :param weeks:【可选】单位：周；类型：整数
    - :return: 返回格式化后的时间

    - 举例：
    | Time Delta | days=5 |
    """
    # 获取当前时间
    now = datetime.datetime.now()

    add_time = now + datetime.timedelta(days=days, seconds=seconds, microseconds=microseconds, milliseconds=milliseconds,
                                        minutes=minutes, hours=hours, weeks=weeks)
    # 格式化字符串输出
    formatted_time = add_time.strftime('%Y-%m-%d %H:%M:%S')
    return formatted_time

def random_chn(length):
    """随机生成中文字符串

    - :param length: 【必填】指定中文字符串的长度
    - :return: 返回生成的字符串
    """
    list1 = ["我", "爱", "他", "轰", "烈", "最", "疯"]
    result = ""
    for i in range(int(length)):
        result += random.choice(list1)
    return result


def random_eng(length):
    """随机生成英文字符串

    - :param length: 【必填】指定英文字符串的长度
    - :return: 返回生成的字符串
    """
    result = ""
    for i in range(int(length)):
        s = chr(random.randint(65, 90))
        result += s
    return result


if __name__ == "__main__":
    a = time_delta(days=-30)#当前日期day为0
    stamp_array = time.strptime(a, '%Y-%m-%d %H:%M:%S')  # 利用strptime()将其转换成时间数组
    stamp = int(time.mktime(stamp_array))*1000  # 转换为时间戳
    print(stamp_array)
    print('本地时间转换成时间戳：', stamp)
    # b = random_eng(5)
    # print (a)


